// page/cart/orderinfo.js
var util = require("../../util/util.js");
Page({
    data: {
        info:[],
        isHide: false
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
      var app = getApp()
      var that = this;
      var uid = wx.getStorageSync('uid');
      wx.request({
        url: app.globalData.host + '&g=App&m=Cart&a=getuinfo', //仅为示例，并非真实的接口地址
        data: {
          uid: uid
        },
        header: {
          'content-type': 'application/json'
        },
        success: function (res) {
          console.log(res.data)
          that.setData({
            info: res.data,
            isHide: true
          })
        }
      })
      
        
    },

    /**
     * 表单验证
     */
    formSubmit: function (e) {
        var app = getApp()
        var uid = wx.getStorageSync('uid');
        var username = e.detail.value.username
        var phone = e.detail.value.phone
      
        if (username.length < 1) {
            util.showToptips("请输入您的姓名", 2000, function () { });
            return;
        } else if (phone.length < 1) {
            util.showToptips("请输入您的手机", 2000, function () { });
            return;
        }  else {
            //成功
          wx.request({
            url: app.globalData.host + '&g=App&m=Cart&a=adduinfo', //仅为示例，并非真实的接口地址
            data: {
              uid: uid, name: username, mobile: phone
            },
            header: {
              'content-type': 'application/json'
            },
            success: function (res) {
              if (res.data.statds) {
                var pages = getCurrentPages();
                var currPage = pages[pages.length - 1];   //当前页面
                var prevPage = pages[pages.length - 2];  //上一个页面

                //直接调用上一个页面的setData()方法，把数据存到上一个页面中去
                prevPage.setData({
                  info: username + phone
                })
                wx.showToast({
                  title: '信息保存成功',
                  icon: 'success',
                  duration: 2000,
                  complete : function (){
                   
                  }
                });
                wx.navigateBack();
              }else{
                util.showToptips("信息没有变更或保存失败", 2000, function () {
                  
                });
              }
            }
          })
        }
    }
})